package com.shaoshaohuo.app.ui.fragment;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.bigkoo.pickerview.TimePickerView;
import com.shaoshaohuo.app.R;
import com.shaoshaohuo.app.adapter.GridViewAdapter;
import com.shaoshaohuo.app.entity.AddNewAddressEntity;
import com.shaoshaohuo.app.entity.BaseEntity;
import com.shaoshaohuo.app.net.ShopHttpConfig;
import com.shaoshaohuo.app.ui.AdderssPOIActivity;
import com.shaoshaohuo.app.ui.BaseActivity;
import com.shaoshaohuo.app.utils.BitmapUtils;
import com.shaoshaohuo.app.utils.Okhttputils;

import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import me.nereo.multi_image_selector.MultiImageSelectorActivity;
import okhttp3.Call;
import okhttp3.Response;

public class ReleaseShopFragment extends Fragment implements View.OnClickListener, View.OnFocusChangeListener {
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    private String mParam1;
    private String mParam2;
    private View view;
    private EditText release_shop_name;
    private EditText release_shop_accept_people;
    private EditText release_shop_details_address;
    private Button release_shop_next;
    private RelativeLayout release_shop_next_relativeLayout;
    private RelativeLayout release_shop_fabu_relativeLayout;

    private String name = "";
    private String address = "";
    private String startHour = "";
    private String endHour = "";
    private String num = "";
    private Button release_shop_fabu;
    private EditText release_shop_big_people_price;
    private EditText release_shop_child_price;
    private EditText release_shop_tuangou_price;
    private EditText release_shop_tuangou_start_people;
    private RelativeLayout release_shop_select_address;
    private TextView release_shop_start_time;
    private TextView release_shop_end_time;
    private TimePickerView timer_select;
    private ImageView release_shop_wifi;
    private TextView release_shop_address;
    private String adult_price = "";
    private String child_price = "";
    private String share_price = "";
    private String start_people = "";
    private LinearLayout release_shop_wifi_linearLayout;
    private String latitude = "";
    private String longitude = "";
    private String province = "";
    private String c = "";
    private String county = "";
    private String wifi = "2";
    private List<File> file;
    private List<String> picture_data;//显示图片
    //上传图片
    private TextView release_shop_cover_page_picture;
    private ImageView release_shop_xianshi_cover_page_picture;
    private TextView release_shop_caizhai_picture;
    private TextView release_shop_caizhai_picture_num;

    private GridView release_shop_grid;
    private GridViewAdapter adapter;
    private boolean wifi_select = true;

    private HorizontalScrollView release_shop_horscrolistView;
    private TextView release_shop_up;
    private View decorView;
    private ScrollView sc;
    private LinearLayout linearLayout;

    public ReleaseShopFragment() {
        // Required empty public constructor
    }


    public static ReleaseShopFragment newInstance(String param1, String param2) {
        ReleaseShopFragment fragment = new ReleaseShopFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_release_shop, container, false);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        sc = (ScrollView) view.findViewById(R.id.sc);
        linearLayout = (LinearLayout) view.findViewById(R.id.lin);
        initView();
        initListener();
        initkeybroad();
    }

    private boolean isvisble = false;

    private void initkeybroad() {
        decorView = getActivity().getWindow().getDecorView();
        decorView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                Rect rect = new Rect();
                decorView.getWindowVisibleDisplayFrame(rect);
                //计算出可见屏幕的高度
                int displayHight = rect.bottom - rect.top;
                //获得屏幕整体的高度
                int hight = decorView.getHeight();
                //获得键盘高度
                int keyboardHeight = hight - displayHight;
                boolean visible = (double) displayHight / hight < 0.8;
                boolean focusable = release_shop_details_address.isClickable();
                boolean release_shop_tuangou_start_peopleClickable = release_shop_tuangou_start_people.isClickable();
                boolean release_shop_tuangou_priceClickable = release_shop_tuangou_price.isClickable();
                if (visible) {
                    if (isfoc) {
                        //当前状态是键盘谈起，根据数据设置scrollview的滚动
//                    ToastUtil.toast("弹起，高度为" + keyboardHeight);
                        isvisble = true;
                        if (focusable) {
                            int bottom = ((View) release_shop_details_address.getParent()).getBottom();
                            int i = keyboardHeight - bottom;
                            if (i > 0) {
                                sc.setTranslationY(-i);
                            }
                        }
                    }
                    if (shareFlag) {
                        isvisble = true;
                        if (release_shop_tuangou_priceClickable) {
                            int bottom1 = linearLayout.getBottom();
                            int i1 = keyboardHeight - bottom1;
                            if (i1 > 0) {
                                release_shop_fabu_relativeLayout.setTranslationY(-i1);
                            }
                        }
                    }
                    if (numBig) {
                        isvisble = true;
                        if (release_shop_tuangou_start_peopleClickable) {
                            int bottom2 = linearLayout.getBottom();
                            int i2 = keyboardHeight - bottom2;
                            if (i2 > 0) {
                                release_shop_fabu_relativeLayout.setTranslationY(-i2);
                            }
                        }
                    }
                }

                if (isvisble && !visible) {
                    isvisble = false;
                    sc.setTranslationY(0);
                    release_shop_fabu_relativeLayout.setTranslationY(0);
                    isfoc = false;
                    numBig = false;
                    shareFlag = false;
                }
            }
        });

    }

    private boolean isfoc = false;
    private boolean numBig = false;
    private boolean shareFlag = false;

    private void initListener() {
        release_shop_next.setOnClickListener(this);
        release_shop_fabu.setOnClickListener(this);
        release_shop_select_address.setOnClickListener(this);
        release_shop_start_time.setOnClickListener(this);
        release_shop_end_time.setOnClickListener(this);
        release_shop_cover_page_picture.setOnClickListener(this);
        release_shop_caizhai_picture.setOnClickListener(this);
        release_shop_wifi_linearLayout.setOnClickListener(this);
        release_shop_up.setOnClickListener(this);
        release_shop_accept_people.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                release_shop_accept_people.setCursorVisible(true);
            }
        });
//        release_shop_tuangou_start_people.setOnTouchListener(new View.OnTouchListener() {
//            @Override
//            public boolean onTouch(View v, MotionEvent event) {
//                release_shop_tuangou_start_people.setCursorVisible(true);
//                return false;
//            }
//        });
        release_shop_details_address.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                isfoc = hasFocus;
            }
        });
        release_shop_details_address.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isfoc = true;
            }
        });
        release_shop_tuangou_start_people.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                numBig = true;
            }
        });
        release_shop_tuangou_start_people.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                numBig = hasFocus;
            }
        });
        release_shop_tuangou_price.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shareFlag = true;
            }
        });
        release_shop_tuangou_price.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                shareFlag = hasFocus;
            }
        });
    }

    private void initView() {
        release_shop_name = (EditText) view.findViewById(R.id.release_shop_name);
        release_shop_accept_people = (EditText) view.findViewById(R.id.release_shop_accept_people);
        release_shop_details_address = (EditText) view.findViewById(R.id.release_shop_details_address);
        release_shop_select_address = (RelativeLayout) view.findViewById(R.id.release_shop_select_address);
        release_shop_next = (Button) view.findViewById(R.id.release_shop_next);
        release_shop_next_relativeLayout = (RelativeLayout) view.findViewById(R.id.release_shop_next_relativeLayout);
        release_shop_fabu_relativeLayout = (RelativeLayout) view.findViewById(R.id.release_shop_fabu_relativeLayout);

        release_shop_big_people_price = (EditText) view.findViewById(R.id.release_shop_big_people_price);
        release_shop_fabu = (Button) view.findViewById(R.id.release_shop_fabu);
        release_shop_child_price = (EditText) view.findViewById(R.id.release_shop_child_price);
        release_shop_tuangou_price = (EditText) view.findViewById(R.id.release_shop_tuangou_price);
        release_shop_tuangou_start_people = (EditText) view.findViewById(R.id.release_shop_tuangou_start_people);
        release_shop_start_time = (TextView) view.findViewById(R.id.release_shop_start_time);
        release_shop_end_time = (TextView) view.findViewById(R.id.release_shop_end_time);
        release_shop_wifi = (ImageView) view.findViewById(R.id.release_shop_wifi);

        release_shop_cover_page_picture = (TextView) view.findViewById(R.id.release_shop_cover_page_picture);
        release_shop_xianshi_cover_page_picture = (ImageView) view.findViewById(R.id.release_shop_xianshi_cover_page_picture);
        release_shop_caizhai_picture = (TextView) view.findViewById(R.id.release_shop_caizhai_picture);
        release_shop_grid = (GridView) view.findViewById(R.id.release_shop_grid);
        release_shop_caizhai_picture_num = (TextView) view.findViewById(R.id.release_shop_caizhai_picture_num);
        file = new ArrayList<>();
        picture_data = new ArrayList<>();
        release_shop_address = (TextView) view.findViewById(R.id.release_shop_address);

        release_shop_wifi_linearLayout = (LinearLayout) view.findViewById(R.id.release_shop_wifi_linearLayout);

        release_shop_horscrolistView = (HorizontalScrollView) view.findViewById(R.id.release_shop_horscrolistView);
        release_shop_up = (TextView) view.findViewById(R.id.release_shop_up);
    }

    private boolean decideHour() {
        String start_word = release_shop_start_time.getText().toString().trim();
        String end_word = release_shop_end_time.getText().toString().trim();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
//        try {
//            Date parse = dateFormat.parse(start_word);
//            long time = parse.getTime();
        if (start_word.compareTo(end_word) >= 0) {
            Toast.makeText(getActivity(), "结束日期应大于开始日期", Toast.LENGTH_SHORT).show();
            return true;
        }

        Calendar calendar = Calendar.getInstance();
        int i = calendar.get(Calendar.YEAR);
        int i1 = calendar.get(Calendar.MONTH) + 1;
        int i2 = calendar.get(Calendar.DAY_OF_MONTH);
        String format = null;
        if (0 < i1 && i1 < 10) {
            String month = "0" + i1;
            format = i + "-" + month + "-" + i2;
        } else {
            format = i + "-" + i1 + "-" + i2;
        }

        Log.e("当前时间", format);
        Log.e("开始时间", start_word);
        Log.e("结束时间", end_word);
        Log.e("三月时间", limitHour(start_word));
        if (format.compareTo(start_word) >= 0) {
            Toast.makeText(getActivity(), "开始日期应大于当天日期", Toast.LENGTH_SHORT).show();
            return true;
        }
        if (format.compareTo(end_word) >= 0) {
            Toast.makeText(getActivity(), "结束日期应大于当天日期", Toast.LENGTH_SHORT).show();
            return true;
        }
        if (limitHour(start_word).compareTo(start_word) >= 0 && limitHour(start_word).compareTo(end_word) <= 0) {
            Toast.makeText(getActivity(), "发布期限应在三个月以内", Toast.LENGTH_SHORT).show();
            return true;
        }
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }
        return false;
    }

    private String limitHour(String string) {
        Date date = null;
        SimpleDateFormat ss = new SimpleDateFormat("yyyy-MM-dd");
        try {
            date = ss.parse(string);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar calendar1 = Calendar.getInstance();
        calendar1.setTime(date);
        calendar1.add(Calendar.MONTH, 3);
        Date time1 = calendar1.getTime();
        SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd");
        String format1 = s.format(time1);
        return format1;
    }

    private ArrayList<String> pathlist = new ArrayList<>();

    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.release_shop_next:
                getShopMessage();
                break;
            case R.id.release_shop_fabu:
                getPriceMessage();
                commitMessage();
                break;
            case R.id.release_shop_select_address:
                Intent intent = new Intent();
                intent.setClass(getContext(), AdderssPOIActivity.class);
                startActivityForResult(intent, 4);
                break;
            case R.id.release_shop_start_time:
                String trim1 = release_shop_end_time.getText().toString().trim();
                Log.e("时间", trim1);
                Calendar selectedDate = Calendar.getInstance();
                Calendar calendar = Calendar.getInstance();
                int year = calendar.get(Calendar.YEAR);
                int month = calendar.get(Calendar.MONTH);
                int day = calendar.get(Calendar.DAY_OF_MONTH);
//                if (trim1.equals("请选择")) {
                Calendar startDate = Calendar.getInstance();
                startDate.set(year, month, day + 1);
                Calendar endDate = Calendar.getInstance();
                endDate.set(year + 1, 11, 28);
                initTimerSelect(startDate, endDate, selectedDate);
                timer_select.show(release_shop_start_time);
//                } else {
//                    Calendar startDate1 = Calendar.getInstance();
//                    startDate1.set(i, 0, 23);
//                    Calendar endDate1 = Calendar.getInstance();
//                    String str[] = trim1.split("-");
//                    int year1 = Integer.parseInt(str[0]);
//                    int day = Integer.parseInt(str[1]);
//                    int month = Integer.parseInt(str[2]);
//                    endDate1.set(year1, month + 1, day);
//                    initTimerSelect(startDate1, endDate1, selectedDate);
//                    timer_select.show(release_shop_start_time);
//                }
                break;
            case R.id.release_shop_end_time:
                String trim = release_shop_start_time.getText().toString().trim();
                Log.e("sta", trim);
                Calendar end_selectedDate = Calendar.getInstance();
                Calendar end_year = Calendar.getInstance();
                int endYear = end_year.get(Calendar.YEAR);
                int end_month = end_year.get(Calendar.MONTH);
                int endDay = end_year.get(Calendar.DAY_OF_MONTH);
//                if (trim.equals("请选择")) {
                Calendar start_Date = Calendar.getInstance();
                start_Date.set(endYear, end_month, endDay + 1);
                Calendar end_Date = Calendar.getInstance();
                end_Date.set(endYear + 1, 11, 28);
                initTimerSelect(start_Date, end_Date, end_selectedDate);
                timer_select.show(release_shop_end_time);
//                } else {
//                Calendar end_date = Calendar.getInstance();
//                end_date.set(endYear + 1, 11, 28);
//                Calendar start_date = Calendar.getInstance();
//                String date_str[] = trim.split("-");
//                int year1 = Integer.valueOf(date_str[0]).intValue();
//                int day = Integer.valueOf(date_str[1]).intValue();
//                int month = Integer.valueOf(date_str[2]).intValue();
//                start_date.set(year1, month + 1, day);
//                initTimerSelect(start_date, end_date, end_selectedDate);
//                timer_select.show(release_shop_end_time);
//                }
                break;
            case R.id.release_shop_wifi_linearLayout:
                decideWifi();
                break;
            case R.id.release_shop_cover_page_picture:
                Intent intent_picture = new Intent();
                tackPic(pathlist, intent_picture, 0, 1);
                intent_picture.setClass(getActivity(), MultiImageSelectorActivity.class);
                startActivityForResult(intent_picture, 2);//封页商品
                break;
            case R.id.release_shop_caizhai_picture:
                Intent intent_caizhai_picture = new Intent();
                tackPic(pathlist, intent_caizhai_picture, 1, 6);
                intent_caizhai_picture.setClass(getActivity(), MultiImageSelectorActivity.class);
                startActivityForResult(intent_caizhai_picture, 3);//采摘商品
                break;
            case R.id.release_shop_up:
                release_shop_fabu_relativeLayout.setVisibility(View.GONE);
                release_shop_next_relativeLayout.setVisibility(View.VISIBLE);
                break;
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 4 && resultCode == 2) {
            AddNewAddressEntity address = (AddNewAddressEntity) data.getSerializableExtra("address");
            if (address != null) {
                String addressname = address.getAddressname();
                release_shop_details_address.setText(addressname);
                release_shop_details_address.setSelection(addressname.length());
                latitude = address.getLatitude();
                longitude = address.getLongitude();
                c = address.getIntent_city();
                address.getProvince();
                province = address.getProvince();
                county = address.getDistrict();
                Log.e("地址", c + province + county);
                Toast.makeText(getActivity(), c + province + county, Toast.LENGTH_SHORT).show();
            }
        }

        if (resultCode == getActivity().RESULT_OK) {
            switch (requestCode) {
                case 2:
                    if (data != null) {
                        ArrayList<String> select_result = data.getStringArrayListExtra("select_result");
                        if (select_result != null && select_result.size() > 0) {
                            String item_picture = select_result.get(0);
                            File zipbit = BitmapUtils.zipbit(item_picture, getContext());
//                            File fil_picture = new File(item_picture);
                            file.add(0, zipbit);
                            Bitmap bitmap = BitmapFactory.decodeFile(zipbit.getAbsolutePath());
                            release_shop_xianshi_cover_page_picture.setVisibility(View.VISIBLE);
                            release_shop_xianshi_cover_page_picture.setImageBitmap(bitmap);
                            release_shop_cover_page_picture.setVisibility(View.GONE);
                        }
                    }
                    break;
                case 3:
                    ArrayList<String> select_more_result = data.getStringArrayListExtra("select_result");
                    if (select_more_result != null && select_more_result.size() > 0) {
                        for (int i = 0; i < select_more_result.size(); i++) {
                            String more_picture = select_more_result.get(i);
//                            File picture_file = new File(more_picture);
                            File zipbit = BitmapUtils.zipbit(more_picture, getContext());
                            file.add(zipbit);
                            picture_data.add(zipbit.getAbsolutePath());
                        }
                        if (picture_data != null && picture_data.size() > 0) {
                            release_shop_horscrolistView.setVisibility(View.VISIBLE);
                            release_shop_caizhai_picture_num.setVisibility(View.GONE);
                            if (picture_data.size() >= 6) {
                                release_shop_caizhai_picture.setVisibility(View.GONE);
                            }
                            adapter = new GridViewAdapter(getActivity(), picture_data);
                            horizontal_layout();
                            release_shop_grid.setAdapter(adapter);
                            adapter.setDelete(new GridViewAdapter.Delete() {
                                @Override
                                public void delete() {
                                    if (adapter.getCount() < 6) {
                                        release_shop_caizhai_picture.setVisibility(View.VISIBLE);
                                    }
                                }
                            });
                        }
                    }
                    break;
            }
        }
    }

    public void horizontal_layout() {
        int size = picture_data.size();
        DisplayMetrics dm = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
        float density = dm.density;
        int allWidth = (int) (110 * size * density);
        int itemWidth = (int) (100 * density);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                allWidth, LinearLayout.LayoutParams.FILL_PARENT);
        release_shop_grid.setLayoutParams(params);// 设置GirdView布局参数
        release_shop_grid.setColumnWidth(itemWidth);// 列表项宽
        release_shop_grid.setHorizontalSpacing(15);// 列表项水平间距
        release_shop_grid.setStretchMode(GridView.NO_STRETCH);
        release_shop_grid.setNumColumns(size);//总长度
    }

    public static void tackPic(ArrayList<String> mSelectPath, Intent intent2, int selectedMode, int maxNum) {
//        int selectedMode = MultiImageSelectorActivity.MODE_MULTI;
//        int maxNum = 10;
//        Intent intent2 = new Intent(mContext, MultiImageSelectorActivity.class);
        // 是否显示拍摄图片
        intent2.putExtra(MultiImageSelectorActivity.EXTRA_SHOW_CAMERA, true);
        // 最大可选择图片数量
        intent2.putExtra(MultiImageSelectorActivity.EXTRA_SELECT_COUNT, maxNum);
        // 选择模式
        intent2.putExtra(MultiImageSelectorActivity.EXTRA_SELECT_MODE, selectedMode);
        // 默认选择
        if (mSelectPath != null && mSelectPath.size() > 0) {
            intent2.putExtra(MultiImageSelectorActivity.EXTRA_DEFAULT_SELECTED_LIST, mSelectPath);
        }

    }

    private void decideWifi() {
        if (wifi_select) {
            wifi = "1";//有
            release_shop_wifi.setImageResource(R.mipmap.payselect);
            wifi_select = false;
        } else if (!wifi_select) {
            wifi = "2";
            release_shop_wifi.setImageResource(R.mipmap.nopayselect);
            wifi_select = true;
        }

    }

    private String getTime(Date date) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        return format.format(date);
    }

    private void initTimerSelect(Calendar startDate, Calendar endDate, Calendar selectedDate) {
        timer_select = new TimePickerView.Builder(getActivity(), new TimePickerView.OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                TextView textView = (TextView) v;
                textView.setText(getTime(date));
            }
        }).setType(new boolean[]{true, true, true, false, false, false})
                .setLabel("年", "月", "日", "", "", "")
                .isCenterLabel(false)
                .setDividerColor(Color.DKGRAY)
                .setContentSize(21)
                .setRangDate(startDate, endDate)
                .setBackgroundId(0x00FFFFFF) //设置外部遮罩颜色
                .setDecorView(null)
                .setDate(selectedDate).build();
    }


    private void commitMessage() {
        Log.e("发布商品", name + address + startHour + endHour + adult_price + num + child_price + share_price);
        if (name == null || name.length() <= 0) {
            Toast.makeText(getActivity(), "商品名称不能为空", Toast.LENGTH_SHORT).show();
        } else if (address == null || address.length() <= 0) {
            Toast.makeText(getActivity(), "地址不能为空", Toast.LENGTH_SHORT).show();
        } else if (startHour == null || startHour.length() <= 0) {
            Toast.makeText(getActivity(), "开始日期不能为空", Toast.LENGTH_SHORT).show();
        } else if (endHour == null || endHour.length() <= 0) {
            Toast.makeText(getActivity(), "结束日期不能为空", Toast.LENGTH_SHORT).show();
        } else if (num == null || num.length() <= 0) {
            Toast.makeText(getActivity(), "可接纳人数不能为空", Toast.LENGTH_SHORT).show();
        } else if (adult_price == null || adult_price.length() <= 0) {
            Toast.makeText(getActivity(), "成人票价格不能为空", Toast.LENGTH_SHORT).show();
        } else if (child_price == null || child_price.length() <= 0) {
            Toast.makeText(getActivity(), "儿童票价格不能为空", Toast.LENGTH_SHORT).show();
        } else if (share_price == null || share_price.length() <= 0) {
            Toast.makeText(getActivity(), "团购票价格不能为空", Toast.LENGTH_SHORT).show();
        } else if (start_people == null || start_people.length() <= 0) {
            Toast.makeText(getActivity(), "团购最大容纳人数不能为空", Toast.LENGTH_SHORT).show();
        } else if (endHour.equals("请选择")) {
            Toast.makeText(getActivity(), "结束日期不能为空", Toast.LENGTH_SHORT).show();
        } else if (startHour.equals("请选择")) {
            Toast.makeText(getActivity(), "开始日期不能为空", Toast.LENGTH_SHORT).show();
        } else if (file.get(0) == null && file.size() <= 2) {
            Toast.makeText(getActivity(), "封页图片需要传一张", Toast.LENGTH_SHORT).show();
        } else if (file.get(1) == null && file.size() <= 2) {
            Toast.makeText(getActivity(), "采摘园图片至少传一张", Toast.LENGTH_SHORT).show();
        } else if (decideHour()) {
        } else if (latitude == null || longitude == null || province == null || county == null || c == null) {
            Toast.makeText(getActivity(), "请选择地址", Toast.LENGTH_SHORT).show();
        } else {
            requestNetData();
        }
    }


    private void requestNetData() {
        ((BaseActivity) getActivity()).startLoadingDialog();
        Log.e("数据", file.size() + "=" + name + "=" + startHour + "=" + endHour + "=" + num + "=" + address + "=" + longitude + "=" + latitude + "=" + adult_price + "=" + child_price + "=" + share_price + "=" + start_people + "=" + province + "=" + c + "=" + county + "=" + wifi);
        ShopHttpConfig.FarmReleaseShop(getActivity(), file, name, startHour, endHour, num, address, longitude, latitude, adult_price, child_price, share_price, start_people, province, c, county, wifi, new Okhttputils.OkutListener() {
            @Override
            public void error(Call call, IOException e) {

            }

            @Override
            public void error(Call call, final int code) {
                getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(getActivity(), "失败" + code, Toast.LENGTH_SHORT).show();
                    }
                });
            }

            @Override
            public void suseff(Call call, final Response response, Object o) {
                Log.e("发布商品", "发布成功");
                ((BaseActivity) getActivity()).dismissLoadingDialog();
                BaseEntity b = (BaseEntity) o;
                final String msg = b.getMsg();
                getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(getActivity(), msg + "发布成功" + response.toString(), Toast.LENGTH_SHORT).show();
                        Intent intent = new Intent();
                        intent.setAction("farmdata");
                        getActivity().sendBroadcast(intent);
                        ViewPager parent = (ViewPager) view.getParent();
                        parent.setCurrentItem(1);
                    }
                });
            }
        }, BaseEntity.class);
    }

    private void getShopMessage() {
        release_shop_next_relativeLayout.setVisibility(View.GONE);
        release_shop_fabu_relativeLayout.setVisibility(View.VISIBLE);
        name = release_shop_name.getText().toString().trim();
        address = release_shop_details_address.getText().toString().trim();
        num = release_shop_accept_people.getText().toString().trim();
        startHour = release_shop_start_time.getText().toString().trim();
        endHour = release_shop_end_time.getText().toString().trim();
    }

    private void getPriceMessage() {
        adult_price = release_shop_big_people_price.getText().toString().trim();
        child_price = release_shop_child_price.getText().toString().trim();
        share_price = release_shop_tuangou_price.getText().toString().trim();
        start_people = release_shop_tuangou_start_people.getText().toString().trim();
    }


    @Override
    public void onFocusChange(View v, boolean hasFocus) {

    }
}
